const http = require("http");

const app = http.createServer();

app.on("request", (req, res) => {
  if (req.url === "/api/todolist") {
    res.writeHead(200, {
      "Content-Type": "application/json;charset=utf-8",
      // 下面代码解决跨域问题
      "Access-Control-Allow-Origin": "*",
      "Access-Control-Allow-Headers": "Content-type",
      "Access-Control-Allow-Methods": "PUT,POST,GET,DELETE,OPTIONS,PATCH",
      "Access-Control-Max-Age": 1728000, //预请求缓存20天
    });
    res.end('["hello","world","fjk666","mockData"]');
  }
});

app.listen(2999, () => {
  console.log("服务器启动 浏览器访问 http://localhost:2999/api/todolist");
});
